﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OpenPhotoAlbum.Maintainance
{
	public partial class Comments : AlbumPage
	{
		private const string ID_HL_USER = "hlUser";
		private const string ID_HL_PHOTO = "hlPhoto";

		protected override void AppendSiteMapNodes(OpenPhotoAlbum.Controls.AlbumSiteMapProvider provider)
		{
			base.AppendSiteMapNodes(provider);

			provider.AppendSiteMapNode("Maintainance Console", "~/Maintainance/Default.aspx");
			provider.AppendSiteMapNode("Latest Submitted Comments", RawUrl);
		}

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			gridView.RowDataBound += new GridViewRowEventHandler(gridView_RowDataBound);
		}

		protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if (e.Row.RowType != DataControlRowType.DataRow) { return; }

			DbAccess.Comment comment = e.Row.DataItem as DbAccess.Comment;
			if (comment == null) { return;}

			HyperLink hlUser = e.Row.FindControl(ID_HL_USER) as HyperLink;
			if (hlUser != null)
			{
				if (comment.UserId == null) { hlUser.Visible = false; }
				else { hlUser.Text = comment.User.UserName; hlUser.NavigateUrl = UrlContext.BuildSharedHomeUrl(comment.User.UserName); }
			}

			HyperLink hlPhoto = e.Row.FindControl(ID_HL_PHOTO) as HyperLink;
			if (hlPhoto != null)
			{
				hlPhoto.Text = "View";
				hlPhoto.NavigateUrl = UrlContext.BuildSharedPhotoUrl(comment.PhotoId);
			}
		}
	}
}
